﻿using Microsoft.AspNetCore.Mvc;
using BCDto.OA.Workflow.WorkflowOperation;
using BCService.OA.TeamWorks.TaskRecordService;
using BlackCoffeeRESTful.Configs;
using BCService.OA.WorkflowEngine;

namespace BlackCoffeeRESTful.Controllers.Management.OA.Workflow
{
    /// <summary>
    /// 工作流操作
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class WorkflowOperationController : ManagementBaseController
    {
        private readonly IWorkflowEngineService workflowEngineService;
        private readonly ITaskRecordService taskRecordService;

        public WorkflowOperationController(IWorkflowEngineService workflowEngineService,
            ITaskRecordService taskRecordService)
        {
            this.workflowEngineService = workflowEngineService;
            this.taskRecordService = taskRecordService;
        }

        /// <summary>
        ///  工作流执行操作
        /// </summary>
        /// <param name="workflowOperationRequestDto">工作流操作信息</param>
        /// <response code="200">工作流执行操作。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("工作流执行操作")]
        public IActionResult Post([FromBody]WorkflowOperationRequestDto workflowOperationRequestDto)
        {
            this.workflowEngineService.Execution(workflowOperationRequestDto);
            return this.Ok(this.taskRecordService.GetEntity(workflowOperationRequestDto.TaskRecordNo));
        }
    }
}
